<?php
$config = Configure::read('Newsletter');
$message = $config['header_message'];
$title = $config['newsletter_title'];
$root_url = FULL_BASE_URL . $this->webroot;

$url_tracking = $mail['Mail']['url_tracking'];

$message_replace = array(
"/%link_view%(.*?)%link_view%/is" => '<a href="' . $root_url . 'newsletter/mails/show/'. $mail['Mail']['id'] . '/' . $url_tracking . '" class="light" style="color:#666666; text-decoration: underline;">$1</a>',
"/%link_unsubscribe%(.*?)%link_unsubscribe%/is" => '<a href="' . $root_url . 'newsletter/subscriptions/unsubscribe/' . $url_tracking . '" class="light" style="color:#666666; text-decoration: underline;">$1</a>',
"/%link_homepage%(.*?)%link_homepage%/is" => '<a href="' . $root_url . $url_tracking . '" class="light" style="color:#666666; text-decoration: underline;">$1</a>'
);

$message = preg_replace(array_keys($message_replace), array_values($message_replace), $message);
?>

<?php //if(isset($readConfirmationCode)):?>
<p class="unsubscribe" style="font-family: arial, sans-serif; font-size: 10px; color:#666666; padding: 5px; text-align: center;">
	<?php echo $message; ?>
</p>
<?php //endif; ?>

<table class="newsletter_header" width="100%" border="0" cellspacing="0" cellpadding="10" style="margin-bottom: 1px; background-color: #eeeeee;">
	<tr>
		<td width="50%" align="left" valign="top">
			<p class="newsletter_info" style="font-family: 'Lucida Grande', 'Trebuchet MS', Trebuchet, Tahoma, sans-serif; font-size: 12px; color: #999; font-weight: bold; margin: 0;">
				<?php echo $title; ?>
			</p>
		</td>
		<td width="50%" align="right" valign="top">
			<p class="newsletter_date" style="font-family: 'Lucida Grande', 'Trebuchet MS', Trebuchet, Tahoma, sans-serif; font-size: 12px; color: #999;margin: 0;">
				<?php __('Date of sending')?> <?php echo date('d.m.Y', $time->toUnix($mail['Mail']['created']));?>
			</p>
		</td>
	</tr>
</table>
<table class="newsletter_content" width="100%" border="0" cellspacing="0" cellpadding="13" style="background-color: #ffffff;">
	<tr>
		<td align="left" valign="top">
			<?php 
			$body = $textile->TextileThis($mail['Mail']['content']); 
			$body = str_replace('<p>','<p class="bodytext" style="font-family: \'Lucida Grande\', \'Trebuchet MS\', Trebuchet, Tahoma, sans-serif; font-size: 12px; color: #555; line-height: 20px; padding-right: 50px;">', $body);
			$body = str_replace('<p class="intro">','<p class="intro" style="font-family: Georgia, Times, serif; font-size: 15px; line-height: 25px; padding-right: 50px; color: #777;">', $body);
			$body = str_replace('<a','<a class="emphesize" style="color: #2b7ea2; text-decoration: underline; padding: 2px; background-color: #f2f2f2;" ', $body);
			$body = str_replace('<img','<img class="body-image" style="margin: 0; border: 3px solid #ddd;"', $body);
			$body = str_replace('<h1>','<h1 style="font-family: \'Helvetica Neue\', Helvetica, sans-serif; font-size: 24px; font-weight: normal; margin-bottom: 10px;">', $body);
			$body = str_replace('<h2>','<h2 style="font-family: \'Helvetica Neue\', Helvetica, sans-serif; font-size: 16px; color: #ff7f00;">', $body);
			$body = str_replace('<h3>','<h3 style="font-family: \'Helvetica Neue\', Helvetica, sans-serif; font-size: 14px; color: #ff7f00;">', $body);
			$body = str_replace('<h4>','<h4 style="font-family: \'Helvetica Neue\', Helvetica, sans-serif; font-size: 12px; color: #ff7f00;">', $body);
			$body = preg_replace('/(?<=href=")([^"]+)(?=[\/]?")/U', "\\1/$url_tracking", $body); //<a href=""  /[?<=href="]([^\"]+)[?="]/m
			echo $body;
			?>
			<p></p>
		</td>
	</tr>
</table>

<?php if(isset($readConfirmationCode)):?>
<img height='1px' width='1px' src="http://<?php echo $_SERVER['HTTP_HOST'] ?>/newsletter/mails/read/<?php echo $readConfirmationCode ?>"/>
<?php endif; ?>
